package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.BaseSaleAttr;
import com.atguigu.gmall.product.entity.BaseTrademark;
import com.atguigu.gmall.product.entity.SpuInfo;
import com.atguigu.gmall.product.service.BaseSaleAttrService;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.atguigu.gmall.product.service.SpuInfoService;
import com.atguigu.gmall.product.vo.SpuInfoVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class SpuController {

    @Autowired
    SpuInfoService spuInfoService;
    @Autowired
    BaseSaleAttrService baseSaleAttrService;
    @Autowired
    BaseTrademarkService baseTrademarkService;
    ///{page}/{limit}?category3Id=61
    @GetMapping("/{page}/{limit}")
    public Result page(@PathVariable("page")Long pn,
                       @PathVariable("limit")Long ps,
                       @RequestParam("category3Id")Long category3Id){
        Page<SpuInfo> page = new Page<>(pn,ps);
        QueryWrapper<SpuInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("category3_id",category3Id);

        Page<SpuInfo> infoPage = spuInfoService.page(page, queryWrapper);

        return Result.ok(infoPage);
    }
    @GetMapping("/baseSaleAttrList")
    public Result baseSaleAttrList(){
        List<BaseSaleAttr> list = baseSaleAttrService.list();
        return Result.ok(list);
    }
    @GetMapping("/baseTrademark/getTrademarkList")
    public Result getTrademarkList(){
        List<BaseTrademark> list = baseTrademarkService.list();
        return Result.ok(list);
    }
    @PostMapping("/saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfoVo spuInfoVo){
        spuInfoService.saveSpuInfo(spuInfoVo);
        return Result.ok();
    }
}
